
app.controller("HousePart", ['$scope', '$stateParams', '$window', '$http', '$cookieStore', '$state', function ($scope, $stateParams, $window, $http, $cookieStore, $state) {

    if ($stateParams.id == 1) {
        $window.document.title = '长租列表'
    } else if ($stateParams.id == 2) {
        $window.document.title = '民宿列表'
    } else if ($stateParams.id == 3) {
        $window.document.title = '营业房列表'
    } else if ($stateParams.id == 4) {
        $window.document.title = '住房出售列表'
    } else {
        $window.document.title = '共享公寓'
    }
    $cookieStore.put('houseStyle', { id: $stateParams.id })
       // 判断登录函数
       $scope.login()




    if ($stateParams.tit != '民宿') {
        if ($cookieStore.get('cityName')) {
            $http({
                method: 'post',
                url: $scope.httptit + '/index/house/lst.html',
                data: {
                    style: $stateParams.id,
                    // lng:$cookieStore.get('lng&lat').lng,
                    // lat:$cookieStore.get('lng&lat').lng,
                    lng: 123.1112232,
                    lat: 113.223,
                    count: 5,
                    page: $scope.pageNum,
                    order: 1,
                    id: $cookieStore.get('cityName').id,
                },
                dataType: 'json',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                transformRequest: $scope.changeData
            }).then(function successCallback(response) {
                if (response.data.status == 102) {
                    $.alert({
                        title: '提示',
                        text: '未检测到数据，请定位后重试',
                        onOK: function () {
                            //点击确认
                        }
                    });
                }
                if (response.data.status == 101) {
                    $scope.PartData = response.data.data;
                    console.log(response.data.data)
                }
                // alert(JSON.stringify(response.data));
            }, function errorCallback(response) {
                console.log(response)

            });
        } else {
            $http({
                method: 'post',
                url: $scope.httptit + '/index/house/lst.html',
                data: {
                    style: $stateParams.id,
                    // lng:$cookieStore.get('lng&lat').lng,
                    // lat:$cookieStore.get('lng&lat').lng,
                    lng: 123.1112232,
                    lat: 113.223,
                    count: 5,
                    page: $scope.pageNum,
                    order: 1,
                },
                dataType: 'json',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                transformRequest: $scope.changeData
            }).then(function successCallback(response) {
                if (response.data.status == 102) {
                    $.alert({
                        title: '提示',
                        text: '未检测到数据，请定位后重试',
                        onOK: function () {
                            //点击确认
                        }
                    });
                }
                if (response.data.status == 101) {
                    $scope.PartData = response.data.data;
                }
                console.log($scope.PartData)
            }, function errorCallback(response) {

            });

        }
    }

    // 下拉加载
    var page = 1;
    var loading = false;  //状态标记
    $("#longRend").infinite().on("infinite", function () {
        if (loading) return;
        loading = true;
        setTimeout(function () {
            $http({
                method: 'post',
                url: $scope.httptit + '/index/house/lst.html',
                data: {
                    style: $stateParams.id,
                    // lng:$cookieStore.get('lng&lat').lng,
                    // lat:$cookieStore.get('lng&lat').lng,
                    lng: 123.1112232,
                    lat: 113.223,
                    count: 5,
                    page: page,
                    order: $cookieStore.get("xlOrder"),
                },
                dataType: 'json',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                transformRequest: $scope.changeData
            }).then(function successCallback(response) {
                if (response.data.status == 102) {
                    $(document.body).destroyInfinite();
                    $scope.closeXL = false;
                }
                if (response.data.status == 101) {
                    console.log(response.data.data)
                    response.data.data.forEach(function (element) {
                        $scope.PartData.push(element);
                    }, this);
                    loading = false;
                    ++page
                }
                console.log($scope.PartData)
            }, function errorCallback(response) {

            });
        }, 1500);   //模拟延迟    
    });

}]);
